package paidaxing.blog.post.controller;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import paidaxing.blog.common.result.PageResult;
import paidaxing.blog.common.result.Result;
import paidaxing.blog.post.entity.UserDemoDTO;
import paidaxing.blog.post.service.DemoService;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/demo")
public class demoController {
    @Resource
    private DemoService demoService;

    /**
     * 分页查询数据(不支持条件筛选)
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult<UserDemoDTO>> queryPage(@RequestParam(defaultValue = "1") Integer pageNo,
                                                     @RequestParam(defaultValue = "10") Integer pageSize) {
        PageResult<UserDemoDTO> pageResult=demoService.queryPage(pageNo,pageSize);
        return Result.success("分页查询成功!", pageResult);
    }


    /**
     * 条件查询列表数据--用于导出、下拉选择等场景
     * @param userDemoDTO
     * @return
     */
    @GetMapping("/list")
    public Result<List<UserDemoDTO>> queryList(UserDemoDTO userDemoDTO) {
        if(log.isInfoEnabled()){
            log.info("条件查询列表数据:{}", userDemoDTO);
        }
        List<UserDemoDTO> list = demoService.queryList(userDemoDTO);
        return Result.success("列表查询成功", list);
    }


    /**
     * 分页查询数据（支持条件筛选）
     * @param userDemoDTO
     * @return
     */
    @GetMapping("/pageList")
    public Result<PageResult<UserDemoDTO>> queryList(UserDemoDTO userDemoDTO,
                                               @RequestParam(defaultValue = "1")Integer pageNo,
                                               @RequestParam(defaultValue = "10")Integer pageSize) {
        if(log.isInfoEnabled()){
            log.info("分页条件查询列表数据--> 条件:{},起始页:{},当前页码大小:{}", userDemoDTO,pageNo,pageSize);
        }
        PageResult<UserDemoDTO> queryPageList = demoService.queryPageList(userDemoDTO,pageNo,pageSize);
        return Result.success("分页条件查询列表数据", queryPageList);
    }




}
